<template>
    <div class="page">
        <p class="title_tip">
          请确认填写的身份信息与身份证信息一致，以免影响就诊人正常就诊！
        </p>
        <i-cell-group>
            <i-cell title="姓名" is-link i-class="cell" >
                <input  placeholder="姓名" v-model="userInfo.Name" slot="footer" type="text" />
            </i-cell>
            <i-cell title="身份证号" is-link i-class="cell" >
                <input  placeholder="身份证号" v-model="userInfo.IdNum" slot="footer" type="idcard" />
            </i-cell>
            <i-cell title="性别" i-class="cell botCell">
                <div slot="footer" class="footer">
                    <div class="radio" @click="chooseMale" style="margin-right:30px">
                        <img :src="checkedImg" alt="" v-if="male">
                        <img :src="not_check" alt="" v-else>
                        <span>男</span>
                    </div>
                    <div class="radio" @click="chooseFemale">
                        <img :src="checkedImg" alt="" v-if="female">
                        <img :src="not_check" alt="" v-else>
                        <span>女</span>
                    </div>
                </div>
            </i-cell>
        </i-cell-group>
        <div class="subBtm">
            <button @click="postStatus = true">提交</button>
        </div>
         <i-toast id="toast" />
      <div class="bg" v-if="postStatus">
        <div class="sure">
          <div class="top">
            <p class="tip">
              请确认填写的身份信息与身份证信息一致，以免影响就诊人正常就诊！
            </p>
            <div class="item">姓名：{{userInfo.Name}}</div>
            <div class="item">身份证：{{userInfo.IdNum}}</div>
            <div class="item">性别：{{female ? '女' : '男'}}</div>
          </div>
          <div class="btm">
            <div @click='postStatus = false'>取消</div>
            <div @click="sureUpload">确定</div>
          </div>
        </div>
      </div>
    </div>
</template>
<script>
import storage from '@/utils/storage'
import api from '@/api/api'
const { $Toast, $Message } = require('../../../../../static/iview/base')
export default {
  data () {
    return {
      male: true,
      female: false,
      userInfo: {},
      imgUrl: '',
      checkedImg: '',
      not_check: false,
      isCommon: true,
      postStatus: false
    }
  },
  mounted () {
    if (this.$route.query.isCommon) {
      this.isCommon = this.$route.query.isCommon
    } else {
      this.isCommon = false
    }
    this.postStatus = false
    this.imgUrl = api.imgUrl
    this.checkedImg = this.imgUrl + 'checked.png'
    this.not_check = this.imgUrl + 'not_check.png'
    this.userInfo = this.$storage.getUserres()
    console.log(this.userInfo, 'userInfo')
    if (this.userInfo.Sex == '男') {
      this.male = true
      this.female = false
    } else {
      this.female = true
      this.male = false
    }
  },
  methods: {
    chooseMale () {
      this.male = true
      this.female = false
    },
    chooseFemale () {
      this.female = true
      this.male = false
    },
    sureUpload () {
      var that = this
      if (this.female == true) {
        this.userInfo.Sex = '女'
      } else if (this.male == true) {
        this.userInfo.Sex = '男'
      } else {
        $Toast({
          content: '请选择性别',
        })
        return
      }
      if (!this.userInfo.Name) {
        $Toast({
          content: '请输入姓名',
        })
        return
      }
      if (!this.userInfo.IdNum) {
        $Toast({
          content: '请输入身份证号',
        })
        return
      }
      var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
      if (!reg.test(this.userInfo.IdNum)) {
        $Toast({
          content: '请输入合法身份证号',
        })
        return
      }
      if (this.userInfo.way == 'cert') {
        if (that.isCommon) {
          // wx.navigateBack({
          //     delta: 2
          // })
          console.log(that.userInfo)
          that.$storage.setUserres(that.userInfo)
          that.$storage.setContact(that.userInfo)
          // that.$router.replace(`/pages/center/child/addCommon/main?is_real=true`)
          let pages = getCurrentPages()//当前页面栈
          console.log(pages, 'pages')
          let prevPage = pages[pages.length - 3]//上两个页面
          // prevPage.setData({'isreal':true, name: '2'});
          that.$storage.setBackParam(true)
          wx.navigateBack({
            delta: 2
          })
          $Toast({
            content: '身份证认证成功',
            type: 'success',
            duration: 0.5
          })
        } else {
          if (!this.userInfo.topKey || !this.userInfo.Nation) {
            $Toast({
              content: '缺少参数,请重新上传身份证人像面清晰图片',
            })
            return
          }
          if (!this.userInfo.btmKey) {
            $Toast({
              content: '缺少参数,请重新上传身份证国徽面清晰图片',
            })
            return
          }
          let param = {
            patient_name: this.userInfo.Name,
            cert_id: this.userInfo.IdNum,
            nation_name: this.userInfo.Nation,
            sex: this.userInfo.Sex,
            cert_front: this.userInfo.topKey,
            cert_back: this.userInfo.btmKey
          }
          that.$api.user_update(param, {'showLoading': true}).then(function (res) {
            that.postStatus = false
            $Toast({
              content: '身份证认证成功',
              type: 'success'
            })
            // that.$docApi.get_doctor_info('', {'showLoading': true}).then(function (res) {
            //   Bus.$emit('changeCard', res.data[0])
            // })
            setTimeout(() => { // ok
              wx.reLaunch({url: '/pages/center/main'})
            }, 1000)
          })
        }
      } else {
        let param = {
          patient_name: this.userInfo.Name,
          cert_id: this.userInfo.IdNum,
          sex: this.userInfo.Sex,
          social_security_cards: this.userInfo.social_security_cards
        }
        that.$api.social_security_verified(param, {'showLoading': true}).then(function (res) {
          $Toast({
            content: '医保卡认证成功',
            type: 'success'
          })
          // that.$docApi.get_doctor_info('', {'showLoading': true}).then(function (res) {
          //   Bus.$emit('changeCard', res.data[0])
          // })
          setTimeout(() => { // ok
            // mpvue.navigateBack(1)
            // that.$router.push("/pages/center/main")
            // wx.redirectTo({url: '/pages/center/main'})
            wx.reLaunch({url: '/pages/center/main'})
          }, 1000)
        })

      }

    }

  }
}
</script>
<style lang='less' scoped>
  .bg {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 999;
    .sure {
      z-index: 2;
      width: 660rpx;
      height: 420rpx;
      overflow: hidden;
      background: #fff;
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -330rpx;
      margin-top: -210rpx;
      border-radius: 8rpx;
      display: flex;
      flex-direction: column;
      font-size: 34rpx;
      .top {
        flex: 1;
        margin: 29rpx 13rpx 0 39rpx;
        .tip {
          font-size:32rpx;
          color:#EE1B1B;
          line-height:51rpx;
          margin-bottom: 11rpx;
        }
        .item {
          height: 53rpx;
          line-height: 53rpx;
          color: #333333;
          font-size: 36rpx;
        }
      }
      .btm {
        height: 90rpx;
        display: flex;
        font-size: 36rpx;
        div {
          flex: 1;
          line-height: 100rpx;
          text-align: center;
          background: #F7F8FA;
        }
        div:nth-child(2) {
          background: #4A64EA;
          color: #fff;
        }
      }
    }
  }
.page{
    width: 100%;
    height: 100%;
    background-color: #F9F9F9;
    box-sizing: border-box
}
.title_tip{
    box-sizing: border-box;
    padding: 24rpx 36rpx 29rpx 30rpx;
    font-size:36rpx;
    color:#EE1B1B;
    line-height:51rpx;
}
.footer{
    display: flex;
    justify-content: flex-start;
    flex-direction: row;
    .radio{
        display: flex;
        justify-content: flex-start;
        flex-direction: row;
        margin-right: 30rpx;
    }
    img{
        width:34rpx;
        height: 34rpx;
        margin: 0 10rpx;
    }
}
 .subBtm {
    width: 92%;
    box-sizing: border-box;
    height: 90rpx;
    margin: 30rpx;
    position: absolute;
    bottom: 30rpx;
    button {
        font-size:34rpx;
        color: #fff;
        height: 90rpx;
        line-height: 90rpx;
        width: 100%;
        background: #3F4ADE;
    }
}

input::-webkit-input-placeholder {
    color: #666!important;
    font-size: 32rpx;
}
/* Mozilla Firefox 4 to 18 */
input:-moz-placeholder {
    color: #666!important;
    opacity: 1;
    font-size: 32rpx;
}
/* Mozilla Firefox 19+ */
input::-moz-placeholder {
    color: #666!important;
    opacity: 1;
    font-size: 32rpx;
}

</style>
